﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="EbaySelling.aspx.cs" Inherits="UI_Orders_EbaySelling" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>ebay销售订单管理</title>
    <link href="../../css/admin.css" rel="stylesheet" type="text/css" />
    <script src="../../js/common.js" type="text/javascript"></script>
    <link href="../../js/jquery.easyui/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../js/jquery.easyui/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../../js/jquery.easyui/jquery.min.js" type="text/javascript"></script>
    <script src="../../js/jquery.easyui/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../js/jquery.easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
    <script src="../../js/FileUpload/ajaxfileupload.js" type="text/javascript"></script>
    
<script type="text/javascript">
    $(function () {
        $("#ddlebayUserId").combobox({
            editable: false
        });

        $("#ddlStatus").combobox({
            editable: false
        });
        var defaultDate = Date.parse('1900/01/01');
        var _$order = $("#order");
        _$order.datagrid({
            border: true,
            height: 345,
            width: 1100,
            title: '订单列表...',
            remoteSort: true,
            nowrap: true,
            striped: false,
            // url: "../../TableHanders.aspx?act=q&tid=41&type=0",
            sortName: 'OrderId',
            sortOrder: 'asc',
            loadMsg: "正在加载,请稍后...",
            frozenColumns: [[
	                { title: 'EbayUserId', field: 'EbayUserId', width: 85, sortable: true, formatter: function (val, rec) {
	                    if (rec.StatusId == 2) {
	                        return '<span style="color:red;">' + val + '</span>';
	                    }
	                    else {
	                        return val;
	                    }
	                }
	                },
	                { title: 'OrderId', field: 'OrderId', width: 180, sortable: true, formatter: function (val, rec) {
	                    if (rec.StatusId == 2) {
	                        return '<span style="color:red;">' + val + '</span>';
	                    }
	                    else {
	                        return val;
	                    }
	                }
	                }
				]],
            columns: [[
	                { title: 'OrderLineItemId', field: 'OrderLineItemId', width: 180, sortable: true },
	                { title: 'SalesRecordNumber', field: 'OrderSalesRecordNumber', width: 130, sortable: true },
	                { title: 'UserId', field: 'UserId', width: 120, sortable: true },
	                { title: 'BuyerFullName', field: 'BuyerFullName', width: 200, sortable: true },
	                { title: 'BuyerEmail', field: 'BuyerEmail', width: 200, sortable: true },
	                { title: 'BuyerAddress1', field: 'BuyerAddress1', width: 200, sortable: true },
	                { title: 'BuyerAddress2', field: 'BuyerAddress2', width: 200, sortable: true },
	                { title: 'BuyerCity', field: 'BuyerCity', width: 120, sortable: true },
	                { title: 'BuyerState', field: 'BuyerState', width: 80, sortable: true },
	                { title: 'BuyerPostcode', field: 'BuyerPostcode', width: 80, sortable: true },
	                { title: 'BuyerCountry', field: 'BuyerCountry', width: 80, sortable: true },
	                { title: 'ItemId', field: 'ItemId', width: 120, sortable: true },
	                { title: 'TransactionID', field: 'TransactionID', width: 120, sortable: true },
	                { title: 'ItemTitle', field: 'ItemTitle', width: 600, sortable: true },
	                { title: 'Quantity', field: 'Quantity', width: 60, sortable: true, align: 'right' },
	                { title: 'SalePrice', field: 'SalePrice', width: 60, sortable: true, align: 'right' },
	                { title: 'FinalValueFee', field: 'FinalValueFee', width: 120, sortable: true, align: 'right' },
	                { title: 'IncludedVATRate', field: 'IncludedVATRate', width: 100, sortable: true },
	                { title: 'PostageAndPackaging', field: 'PostageAndPackaging', width: 125, sortable: true, align: 'right' },
	                { title: 'Insurance', field: 'Insurance', width: 60, sortable: true, align: 'right' },
	                { title: 'TotalPrice', field: 'TotalPrice', width: 60, sortable: true, align: 'right' },
	                { title: 'PaymentMethod', field: 'PaymentMethod', width: 90, sortable: true },
	                { title: 'PayPalTransactionID', field: 'PayPalTransactionID', width: 130, sortable: true },
	                { title: 'InvoiceNumber', field: 'InvoiceNumber', width: 90, sortable: true },

					{ field: 'InvoiceDate', title: 'InvoiceDate', width: 130, sortable: true, formatter: function (val) {
					    var d = Date.parse(val.replace("-", "/"));
					    if (d == defaultDate) {
					        return "";
					    }
					    else {
					        return val;
					    }
					}
					},
					{ field: 'SaleDate', title: 'SaleDate', width: 130, sortable: true, formatter: function (val) {
					    var d = Date.parse(val.replace("-", "/"));
					    if (d == defaultDate) {
					        return "";
					    }
					    else {
					        return val;
					    }
					}
					},
					{ field: 'CheckoutDate', title: 'CheckoutDate', width: 130, sortable: true, formatter: function (val) {
					    var d = Date.parse(val.replace("-", "/"));
					    if (d == defaultDate) {
					        return "";
					    }
					    else {
					        return val;
					    }
					}
					},
					{ field: 'PaidonDate', title: 'PaidonDate', width: 130, sortable: true, formatter: function (val) {
					    var d = Date.parse(val.replace("-", "/"));
					    if (d == defaultDate) {
					        return "";
					    }
					    else {
					        return val;
					    }
					}
					},
					{ field: 'DispatchDate', title: 'DispatchDate', width: 130, sortable: true, formatter: function (val) {
					    var d = Date.parse(val.replace("-", "/"));
					    if (d == defaultDate) {
					        return "";
					    }
					    else {
					        return val;
					    }
					}
					},
					{ field: 'PostageService', title: 'PostageService', width: 200, sortable: true },
					{ field: 'FeedbackLeft', title: 'FeedbackLeft', width: 80, sortable: true },
					{ field: 'NotestoYourself', title: 'NotestoYourself', width: 85, sortable: true },
					{ field: 'CustomLabel', title: 'CustomLabel', width: 200, sortable: true },
					{ field: 'PrivateNotes', title: 'PrivateNotes', width: 85, sortable: true },
					{ field: 'ProductIDType', title: 'ProductIDType', width: 85, sortable: true },
					{ field: 'ProductIDValue', title: 'ProductIDValue', width: 85, sortable: true },
					{ field: 'ProductIDValue2', title: 'ProductIDValue2', width: 85, sortable: true },
					{ field: 'VariationSKU', title: 'VariationSKU', width: 200, sortable: true },
					{ field: 'Variation_Name', title: 'Variation_Name', width: 85, sortable: true },
					{ field: 'Variation_Value', title: 'Variation_Value', width: 85, sortable: true },
					{ field: 'VariationTitle', title: 'VariationTitle', width: 300, sortable: true },
					{ field: 'VariationViewItemURL', title: 'VariationViewItemURL', width: 300, sortable: true },
					{ field: 'eBayPaymentStatus', title: 'eBayPaymentStatus', width: 120, sortable: true },
					{ field: 'BuyerSelectedShipping', title: 'BuyerSelectedShipping', width: 150, sortable: true },
					{ field: 'FeedbackScore', title: 'FeedbackScore', width: 120, sortable: true, align: 'right' },
					{ field: 'PositiveFeedbackPercent', title: 'PositiveFeedbackPercent', width: 150, sortable: true, align: 'right' },
					{ field: 'ExternalTransactionTime', title: 'ExternalTransactionTime', width: 150, sortable: true, formatter: function (val) {
					    var d = Date.parse(val.replace("-", "/"));
					    if (d == defaultDate) {
					        return "";
					    }
					    else {
					        return val;
					    }
					}
					},
					{ field: 'FeeOrCreditAmount', title: 'FeeOrCreditAmount', width: 110, sortable: true, align: 'right' },
					{ field: 'PaymentOrRefundAmount', title: 'PaymentOrRefundAmount', width: 150, sortable: true, align: 'right' },
					{ field: 'Platform', title: 'Platform', width: 85, sortable: true },
	                { title: 'CompleteStatus', field: 'CompleteStatus', width: 130, sortable: true },
					{ field: 'CheckoutStatus', title: 'CheckoutStatus', width: 120, sortable: true },
					{ field: 'LastTimeModified', title: 'LastTimeModified', width: 100, sortable: true, formatter: function (val) {
					    var d = Date.parse(val.replace("-", "/"));
					    if (d == defaultDate) {
					        return "";
					    }
					    else {
					        return val;
					    }
					}
					},
					{ field: 'SellingStatus', title: '状态', width: 50, sortable: true, formatter: function (val, rec) {
					    if (val == 2) {
					        return '<span style="color:red;">已匹配</span>';
					    }
					    else if (val == 1) {
					        return '新导入';
					    }
					    else if (val == 3) {
					        return '已作废';
					    }
					    else {
					        return val;
					    }
					}
					}
				]],
            pagination: true,
            rownumbers: true,
            singleSelect: true,
            pageList: [10, 15, 20],
            onDblClickRow: function (rowIndex, rowData) {
                var id = rowData.EbayUserId;
                var id2 = rowData.OrderLineItemId;
                window.showModalDialog("EbaySellingDetail.aspx?act=view&id=" + id + "&id2=" + id2 + "&ts=" + new Date().getTime(), "", "dialogHeight:600px;dialogWidth:710px;edge:Raised;center:Yes;help:No;resizable:no;status:no; scroll:no;location=no;");
            },
            queryParams: {
                "timeFrom": $("#beginDate").datebox('getValue'),
                "timeTo": $("#endDate").datebox('getValue'),
                "EbayUserId": $("#ddlebayUserId").combobox('getValue'),
                "OrderStatus": $("#ddlStatus").combobox('getValue'),
                "OrderId": $("#txtOrderId").val()
            }
        });
        $("#btnQuery").click(function () {
            if (!$("#p").form('validate'))
                return;
            var timeFrom = $("#beginDate").datebox('getValue');
            var timeTo = $("#endDate").datebox('getValue');
            var EbayUserId = $("#ddlebayUserId").combobox('getValue');
            var orderStatus = $("#ddlStatus").combobox('getValue');
            var orderId = $("#txtOrderId").val();
            _$order.datagrid({
                url: "../../TableHanders.aspx?act=q&tid=41&type=0",
                queryParams: {
                    "timeFrom": timeFrom,
                    "timeTo": timeTo,
                    "EbayUserId": EbayUserId,
                    "OrderStatus": orderStatus,
                    "OrderId": orderId
                }
            });
        });
        $('#beginDate').datebox({ formatter: function (date) {
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            var d = date.getDate();
            return y + "-" + m + "-" + d;
        }
        });
        $('#endDate').datebox({ formatter: function (date) {
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            var d = date.getDate();
            return y + "-" + m + "-" + d;
        }
        });

        function ajaxFileUploads() {
            $.ajaxFileUpload(
                   {
                       url: '../../UpLoadFile.ashx?type=excel&tid=41&id=' + new Date().getTime(),
                       secureuri: false,
                       fileElementId: 'fup',
                       dataType: 'text',
                       success: function (data, status) {
                           var retData = EvalData(data);
                           if (retData.retCode = 0) {
                               alert('成功导入!');
                           }
                           else {
                               alert(retData.retMsg);
                           }
                       },
                       error: function (data, status, e) {
                           alert("更新失败!");
                       }
                   });
        }

        $("#btnImPort").click(function () {
            //            alert('尚在开发中');
            //            return;
            var file = $("#fup");
            var filePath = getPath(file);
            if (filePath == "") {
                alert("请选择一个excel文件");
                return;
            }
            var strRegex = "(.xls)$";
            var re = new RegExp(strRegex);

            if (!re.test(filePath)) {
                alert("只支持*.xls文件");
                clearvalue(file);
                return;
            }
            ajaxFileUploads();
        });
    });
</script>
</head>
<body>
    <form id= "fomrquery" runat="server" style ="width :1100px;" >
    <div class="div_Title">
        <span class="Body_Title">》》<%=this.Title %></span>
    </div>    
    <div id="p" class="easyui-panel" title="请输入查询条件..." style="margin-bottom:5px">
        <table>
            <tr>
                <td>订单号:</td>
                <td>
            	    <input id="txtOrderId" runat="server" style="width:200px;" />
                </td>
                <td>ebay帐号:</td>
                <td>
            	    <select  id="ddlebayUserId" runat="server" class="easyui-combobox" style="width:200px;"></select>
                </td>
                <td>导入日期:</td>
                <td>
                    <input id="beginDate" type="text" class ="easyui-datebox" runat="server"  required="true" readonly="readonly" style="width:90px"/>
                </td>
                <td> - </td>
                <td>
                    <input id="endDate" type="text" class ="easyui-datebox" runat="server"  required="true" readonly="readonly" style="width:90px"/>
                </td>
                <td>订单状态</td>
                <td>
            	    <select id="ddlStatus" runat="server" class="easyui-combobox" required="true" style="width:120px"></select>
                </td>               
                <td>
                    <a id="btnQuery" href="#" class="easyui-linkbutton" icon="icon-search">Query</a>
                </td>
            </tr>
        </table>
    </div>
    <table id="order"  runat ="server" ></table>
    <div style="margin-top:5px">
        <div id="p1" class="easyui-panel" title="数据导入..." runat="server">
            <table>
                <tr>
                    <td>选择文件:</td>
                    <td>
            	        <input type="file" id="fup" name="fup" style="width:500px"/>
                    </td>
                    <td>
                    <a id="btnImPort" class = "easyui-linkbutton"  icon="icon-reload">导入</a>
                    <asp:LinkButton ID="btnExport" CssClass = "easyui-linkbutton"  icon="icon-redo" 
                            Text="导出" runat="server" onclick="btnExport_Click"></asp:LinkButton>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    </form>
</body>
</html>
